package com.accloud.cloudservice;

import com.accloud.service.ACDeviceFind;
import com.accloud.service.Receiver;
import com.accloud.utils.LocalUtils;
import java.nio.ByteBuffer;

public class AbleLinkingFind extends AbleFind {
    private static final int PCT_STATE_CONNECT_CLOUD = 6;
    private int x;

    public AbleLinkingFind(int timeout_ms, int interval_ms, Receiver<ACDeviceFind> receiver) {
        super(timeout_ms, interval_ms, receiver);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:13:0x0027, code lost:
        r7 = parseFindDevice(r9.payload, r9.version);
     */
    @Override // com.accloud.cloudservice.AbleFind
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void onReceive(com.accloud.cloudservice.LocalMessage r9) {
        /*
            r8 = this;
            r3 = 0
            r4 = 4
            byte r0 = r9.version
            if (r0 > r4) goto L_0x001d
            int r0 = r9.msgCode
            r1 = 27
            if (r0 != r1) goto L_0x001d
            com.accloud.service.ACDeviceFind r7 = parseLinkDevice(r9)
            if (r7 != 0) goto L_0x0013
        L_0x0012:
            return
        L_0x0013:
            com.accloud.service.Receiver r0 = r8.receiver
            if (r0 == 0) goto L_0x0012
            com.accloud.service.Receiver r0 = r8.receiver
            r0.onReceive(r7)
            goto L_0x0012
        L_0x001d:
            byte r0 = r9.version
            if (r0 <= r4) goto L_0x0012
            int r0 = r9.msgCode
            r1 = 31
            if (r0 != r1) goto L_0x0012
            byte[] r0 = r9.payload
            byte r1 = r9.version
            com.accloud.service.ACDeviceFind r7 = parseFindDevice(r0, r1)
            if (r7 == 0) goto L_0x0012
            com.accloud.cloudservice.LocalMessage r2 = new com.accloud.cloudservice.LocalMessage
            r0 = 3
            r2.<init>(r0, r3)
            int r0 = r8.x
            r1 = 10
            if (r0 <= r1) goto L_0x0055
            r0 = 0
        L_0x003e:
            r8.x = r0
            com.accloud.cloudservice.ACDeviceLocalManager r0 = com.accloud.cloudservice.AC.deviceLocalManager
            java.lang.String r1 = r7.getIp()
            r4 = 2000(0x7d0, float:2.803E-42)
            int r5 = r8.x
            int r5 = r5 + 6691
            com.accloud.cloudservice.AbleLinkingFind$1 r6 = new com.accloud.cloudservice.AbleLinkingFind$1
            r6.<init>(r7)
            r0.sendDeviceByUdp(r1, r2, r3, r4, r5, r6)
            goto L_0x0012
        L_0x0055:
            int r0 = r8.x
            int r0 = r0 + 1
            goto L_0x003e
        */
        throw new UnsupportedOperationException("Method not decompiled: com.accloud.cloudservice.AbleLinkingFind.onReceive(com.accloud.cloudservice.LocalMessage):void");
    }

    private static ACDeviceFind parseLinkDevice(LocalMessage message) {
        ByteBuffer buffer = ByteBuffer.wrap(message.payload);
        long majorDomainId = LocalUtils.parseLong(LocalUtils.iterateBytes(buffer, 6));
        long subDomainId = LocalUtils.parseLong(LocalUtils.iterateBytes(buffer, 2));
        String physicalDeviceId = new String(LocalUtils.iterateBytes(buffer, message.version == 1 ? 16 : buffer.remaining()));
        if (isValid(majorDomainId)) {
            return new ACDeviceFind(subDomainId, "0.0.0.0", physicalDeviceId);
        }
        return null;
    }
}
